package service;

import dao.PilotDAOImpl;
import logic.Pilot;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import java.util.List;
import java.util.Map;

/**
 * Created by Vovancho on 08.12.2014.
 */
@ManagedBean
@SessionScoped
public class PilotServiceImpl extends Pilot  {

    private PilotDAOImpl pilotDAOI = new PilotDAOImpl();
    private List<Pilot> pilots;

    public List<Pilot> getPilots() {
        return pilots;
    }

    public void setPilots(List<Pilot> pilots) {
        this.pilots = pilots;
    }

    public void addPilot() {
        pilotDAOI.addPilot(new Pilot(getFirstName(),getMiddleName(),getLastName()));
    }
//@PostConstruct
    public void listPilot() {
        pilots = pilotDAOI.listPilot();
    }

    public  List<Pilot> pilotById(int pilotId){
      return pilotDAOI.getPilotById(pilotId);
    }

    public void removePilot() {
        FacesContext context = FacesContext.getCurrentInstance();
        Map<String, String> map = context.getExternalContext().getRequestParameterMap();
        Integer id = new Integer(map.get("pilotId"));
        pilotDAOI.removePilot(id);
    }
}
